pylxd/models/instance: Support selective state recursion in Instance.all()#707
pylxd/models/instance: Support selective state recursion in Instance.all()#707gajeshbhat wants to merge 6 commits intocanonical:mainfrom
Conversation
|
@gajeshbhat at first glance it looks really good. Let's see if Copilot picks something up. May I ask you to split your commits a bit more, at least one per file and please commit unrelated changes into their own commits (like dropping the trailing spaces in doc). Thanks! |
There was a problem hiding this comment.
Pull request overview
Adds selective state recursion support to Instance.all() so callers can request only specific instance state sub-fields (when supported by the LXD server), reducing data transfer and avoiding expensive state collection.
Changes:
- Extend
Instance.all()with afieldsparameter and conditional use ofinstances_state_selective_recursion. - Add unit tests covering selective-recursion URL construction and fallback behavior.
- Add integration tests and documentation describing
recursion/fieldsusage and behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
pylxd/models/instance.py |
Adds fields argument and selective-recursion query parameter formatting when the server supports the extension. |
pylxd/models/tests/test_instance.py |
Adds unit tests for selective recursion query encoding, multi-field joining, empty fields, and fallback/ignore paths. |
integration/test_instances.py |
Adds integration coverage for instances.get() and instances.all() including selective-recursion scenarios (skipping when unsupported). |
doc/source/instances.rst |
Documents all(recursion=0, fields=None) and provides examples for selective recursion behavior and fallback. |
CONTRIBUTORS.rst |
Adds a contributor entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Thank you @simondeziel . Definitely will make those changes and get this updated soon. :) |
Signed-off-by: Gajesh Bhat <gajeshbht@gmail.com>
Signed-off-by: Gajesh Bhat <gajeshbht@gmail.com>
…all() Add a `fields` parameter to `Instance.all()` that enables the LXD selective state recursion feature (instances_state_selective_recursion). When `recursion=2` and `fields` is provided, the query parameter is encoded as `recursion=2;fields=<comma-joined-fields>`, which tells LXD to return only the requested state sub-fields (e.g. state.disk, state.network). This significantly reduces data transfer for callers that only need a subset of instance state. If the server does not advertise the required extension, the call gracefully falls back to a standard `recursion=2` request. Explicit input validation rejects bare str/bytes values and non-string iterable elements, raising TypeError with a clear message. Signed-off-by: Gajesh Bhat <gajeshbht@gmail.com>
…sion Add eight unit tests covering: - selective URL construction for a single field - selective URL construction for multiple fields - empty fields list (suppress all state fields) - graceful fallback when extension is absent - fields silently ignored when recursion != 2 - TypeError raised for bare str fields argument - TypeError raised for bytes fields argument - TypeError raised when iterable contains non-string element Signed-off-by: Gajesh Bhat <gajeshbht@gmail.com>
…all() Document the new `fields` parameter added to Instance.all(), including: - updated manager method list with recursion and fields descriptions - code examples for plain recursion=2, single-field, multi-field, and empty-fields selective recursion - note on graceful fallback when the extension is absent Signed-off-by: Gajesh Bhat <gajeshbht@gmail.com>
Add integration tests covering: - get() by name - all() at recursion levels 0, 1, and 2 - selective recursion with state.disk (skipped if extension absent) - selective recursion with state.disk and state.network (skipped if extension absent) - empty fields list (skipped if extension absent) - graceful fallback when instances_state_selective_recursion is absent (skipped if extension is present) Signed-off-by: Gajesh Bhat <gajeshbht@gmail.com>
b171ce8 to
89442a1
Compare
Fixed these copilot suggestions. CC: @simondeziel |
Summary
Add a
fieldsparameter toInstance.all()to support the LXD selective state recursion feature introduced via theinstances_state_selective_recursionAPI extension.When
recursion=2and afieldslist is provided, the request uses therecursion=2;fields=<comma-joined>query syntax, which instructs LXD to return only the requested state sub-fields. This avoids fetching expensive data (e.g. full network enumeration) when only a subset is needed.If the server does not advertise the
instances_state_selective_recursionextension, the call silently falls back to a standardrecursion=2request.Usage
References
Fixes #706